# # -*- coding: utf-8 -*-
# from datetime import timedelta
# from jms.dm.dm_agg_collect_aging_dt import jms_dm__dm_agg_collect_aging_dt
# from utils.alerts.doris_telnet_check import net_is_used
# from utils.operators.rich_sql_sensor import RichSqlSensor
#
# label = "dws_agg_collect_aging_{{ execution_date | cst_ds_nodash }}_{{ ti.try_number }}"
# timeout = timedelta(minutes=10).seconds
# dorisConn = net_is_used()
# doris_jms_dws__dws_agg_collect_aging = RichSqlSensor(
#     task_id='doris_jms_dws__dws_agg_collect_aging',
#     email='lukunming@jtexpress.com',
#     pool='broker_load_pool',
#     conn_id='doris',
#     pre_sql=f"""
#              TRUNCATE TABLE jms_dws.dws_agg_collect_aging PARTITION (p{{{{ execution_date | date_add(-1) | cst_ds_nodash }}}});
#              LOAD LABEL jms_dws.{label} (
#                  DATA INFILE("hdfs://yl-bg-hdp/dw/hive/jms_dm.db/external/dm_agg_collect_aging_dt/dt={{{{ execution_date | date_add(-1) | cst_ds }}}}/*")
#                  INTO TABLE dws_agg_collect_aging
#                  FORMAT AS 'PARQUET'
#                  (taking_network_id,taking_network_code,taking_network_name,entrepot_network_id,entrepot_network_code,entrepot_network_name,center_id,center_code,center_name,goods_type_id,goods_type_code,goods_type_name,order_source_code,order_source_name,sub_source_code,taking_regional_id,taking_regional_desc,taking_provider_id,taking_provider_desc,taking_city_id,taking_city_desc,taking_agent_id,taking_agent_code,taking_agent_name,taking_first_franchisee_id,taking_first_franchisee_code,taking_first_franchisee_name,taking_second_franchisee_id,taking_second_franchisee_code,taking_second_franchisee_name,full_cnt,center_in_time_cnt,entrepot_in_time_cnt,network_duty_cnt,entrepot_duty_cnt)
#                  SET (collect_start_date = DATE('{{{{ execution_date | date_add(-1) | cst_ds }}}}'))
#              )
#              WITH BROKER '{{{{ var.json.doris_brokers | random_choice }}}}'
#              PROPERTIES ('timeout'='{timeout}', 'max_filter_ratio'='0.0')""",
#     poke_sql=f"SHOW LOAD FROM jms_dws WHERE label = '{label}' ORDER BY CreateTime DESC LIMIT 1",
#     sql_on_kill=f"CANCEL LOAD FROM jms_dws WHERE LABEL = '{label}'",
#     success=lambda r: r[2] == 'FINISHED',
#     failure=lambda r: (r[2] is not None and r[2] == 'CANCELLED', str(r[7])),
#     poke_interval=60,
#     execution_timeout=timedelta(seconds=timeout + 120), )
#
# doris_jms_dws__dws_agg_collect_aging << jms_dm__dm_agg_collect_aging_dt
